/**
 * 用户相关服务
 */
const util = require('./util.js');
const api = require('../config/api.js');

/**
 * Promise封装uni.checkSession
 */
function checkSession() {
    return new Promise(function (resolve, reject) {
        uni.checkSession({
            success: function () {
                resolve(true);
            },
            fail: function () {
                reject(false);
            }
        });
    });
}

/**
 * Promise封装uni.login
 */

/**
 * 判断用户是否登录
 */
function checkLogin() {
    return new Promise(function (resolve, reject) {
        if (uni.getStorageSync('userInfo') && uni.getStorageSync('token')) {
            checkSession()
                .then(() => {
                    resolve(true);
                })
                .catch(() => {
                    reject(false);
                });
        } else {
            reject(false);
        }
    });
}
module.exports = {
    checkLogin
};
